package com.numberone.iotplatform.config;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class ResourceConfig implements WebMvcConfigurer {

    @Value("${file.upload-dir}")
    private String uploadDir;

    /**
     * 配置静态资源映射
     * 将 URL 路径 /uploads/** 映射到磁盘上的物理路径
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 注意：这里的路径是相对于 context-path (/api) 的
        // 所以最终访问URL是 http://.../api/uploads/文件名
        registry.addResourceHandler("/uploads/**")
                .addResourceLocations("file:" + uploadDir);
    }
}